const BASE_URL = 'https://tea.qingnian8.com/api/bizhi'

export function request(config={}) {
	return new Promise((resolve,reject) => {
		let {
			url,
			method = "GET",
			data = null,
			header = {}
		} = config;
		header['access-key'] = "dxq123";
		header['Content-Type'] = "application/json;charset=UTF-8";
		url = BASE_URL + url
		uni.request({
			url,
			method,
			data,
			header,
			success(res) {
				if (res.data.errCode === 0) {
					resolve(res.data)
				} else if (res.data.errCode === 400){
					uni.showModal({
						title: "错误提示",
						content: res.data.errMsg,
						showCancel: false
					})
					reject(res.data)
				} else {
					uni.showToast({
						title: res.data.errMsg,
						icon: "none"
					})
					reject(res.data)
				}
			},
			fail(err) {
				reject(err)
			}
		})
	})
}